home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / ATOH.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  2KB  |  127 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ;
  9. ; ATOH-    Converts the hexadecimal string pointed at by ES:DI to an integer
  10. ;    and returns it in the AX register.
  11. ;
  12. ;    Returns with the carry flag clear if no error, set if overflow.
  13. ;
  14. ; ATOH- preserves di.  ATOH2- Leaves di pointing at first char beyond
  15. ;    hex data.
  16. ;
  17.         public    sl_atoh
  18. sl_atoh        proc    far
  19.         push    di
  20.         call    far ptr sl_atoh2
  21.         pop    di
  22.         ret
  23. sl_atoh        endp
  24. ;
  25.         public    sl_atoh2
  26. sl_atoh2    proc    far
  27.         pushf
  28.         cld
  29.         push    cx
  30.         xor    cx, cx
  31. CnvrtLp:    mov    al, es:[di]
  32.         inc    di
  33.         cmp    al, 'a'
  34.         jb    SkipConvert
  35.         and    al, 5fh
  36. ;
  37. SkipConvert:    xor    al, '0'
  38.         cmp    al, 10
  39.         jb    GotDigit
  40.         add    al, 89h                ;A->0fah.
  41.         cmp    al, 0fah
  42.         jb    Done
  43.         and    al, 0fh                ;0fa..0ff->a..f
  44. GotDigit:    shl    cx, 1                ;Make room for new
  45.         jc    Overflow            ; nibble.
  46.         shl    cx, 1
  47.                 jc    Overflow
  48.         shl    cx, 1
  49.                 jc    Overflow
  50.         shl    cx, 1
  51.         jc    Overflow
  52.         or    cl, al                ;Add in new nibble.
  53.         jmp    CnvrtLp
  54. ;
  55. Overflow:    stc
  56.         jmp    short WasError
  57. ;
  58. Done:        clc
  59. WasError:    mov    ax, cx
  60.         pop    cx
  61.         popf
  62.         ret
  63. sl_atoh2    endp
  64. ;
  65. ;
  66. ; AtoLH - Converts a string of up to 8 hex digits into a long integer
  67. ;      value and returns the result in DX:AX.
  68. ;
  69. ; AtoH- preserves di.  AtoH2- Returns with di pointing at the first char
  70. ;    beyond the string.
  71. ;
  72. sl_atolh    proc    far
  73.         push    di
  74.         call    far ptr sl_atolh2
  75.         pop    di
  76.         ret
  77. sl_atolh    endp
  78. ;
  79. ;
  80.         public    sl_atolh2
  81. sl_atolh2    proc    far
  82.         pushf
  83.         cld
  84.         push    cx
  85.         xor    cx, cx
  86.                 mov    dx, cx
  87. CnvrtLp2:          mov    al, es:[di]
  88.         inc    di
  89.         and    al, 05fh            ;l.c. -> U.C.
  90.         xor    al, '0'
  91.         cmp    al, 10
  92.         jb    GotDigit2
  93.         add    al, 89h                ;A->10.
  94.         cmp    al, 0fah
  95.         jb    Done2
  96.         and    al, 0fh
  97. GotDigit2:    shl    cx, 1                ;Make room for new
  98.         rcl    dx, 1                           ; nibble.
  99.         jc    Overflow2
  100.         shl    cx, 1
  101.         rcl    dx, 1
  102.         jc    Overflow2
  103.         shl    cx, 1
  104.         rcl    dx, 1
  105.         jc    Overflow2
  106.         shl    cx, 1
  107.         rcl    dx, 1
  108.         jc    Overflow2
  109.         or    cl, al                ;Add in new nibble.
  110.         jmp    CnvrtLp2
  111. ;
  112. Overflow2:    stc
  113.         jmp    short WasError2
  114. ;
  115. Done2:        clc
  116. WasError2:    mov    ax, cx
  117.         pop    cx
  118.         popf
  119.         ret
  120. sl_atolh2    endp
  121. ;
  122. ;
  123. ;
  124. ;
  125. stdlib        ends
  126.         end
  127.